<?php
/**
 * Created by PhpStorm.
 * User: tengwei
 * Date: 2018/11/16
 * Time: 10:17 AM
 */

namespace common\sources\read\businessaccount;

use common\models\craftsman\BusinessAccount;

class BusinessAccountAccess implements IBusinessAccountAccess
{
    public function orderBalanceBank($data) {
        $result = BusinessAccount::find()
            ->select("phone,total_deposit,ava_deposit,ava_pepper,freezing_golds,create_time,freezing_deposit")
            ->leftJoin('buyuser','buyuser.id = business_account.bus_id')
            ->where("buyuser.role = " . $data['role'])
            ->limit($data['limit'])
            ->orderBy("total_deposit desc")
            ->asArray()
            ->all();
        return $result;
    }

    public function getBusinessAccount($bus_id) {
        $account = BusinessAccount::find()
            ->select("bus_id,total_deposit,ava_deposit,ava_pepper,freezing_golds,create_time,freezing_deposit,cash_deposit")
            ->where(['bus_id' => $bus_id])
            ->asArray()
            ->one();
        return $account;
    }

    public function allBuyUserAccount($ids) {
        return BusinessAccount::find()
            ->alias('b')
            ->select("b.bus_id,b.ava_pepper,b.ava_deposit,b.freezing_golds,b.total_deposit,u.phone,u.role")
            ->leftJoin('buyuser u','u.id = b.bus_id')
            ->where(['bus_id' => $ids])
            ->indexBy('bus_id')
            ->asArray()
            ->all();
    }
}